﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CMP.ERP.Model;
using System.Data;
using CMP.ERP.Helper;
using System.Data.SqlClient;

namespace CMP.ERP.DAL
{
    public class Role_Option1DAL
    {

        SQLHelper helper = new SQLHelper();
       
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <returns></returns>
        public DataTable Role()
        {
            string ProcName = "select * from Role1";

            return helper.ExecDataTable(ProcName);
        }
        
        /// <summary>
        /// 根据ID获取权限
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public DataTable Option(int pid)
        {
            string ProcName = "Proc_GetOptionByid";
            SqlParameter[] commandParameters = new SqlParameter[1]
            {
                new SqlParameter("@Pid",pid)
            };
            return helper.ExecDataTable_Proc(ProcName, commandParameters);
        }
        /// <summary>
        /// 根据角色编号获取权限编号
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        public DataTable getOidbyrid(int rid)
        {
            string ProcName = "Proc_GetOidByRid";
            SqlParameter[] commandParameters = new SqlParameter[1]
            {
                new SqlParameter("@Rid",rid)
            };
            return helper.ExecDataTable_Proc(ProcName, commandParameters);
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        public int update(int rid)
        {
            string ProcName = "Proc_Update";
            SqlParameter[] commandParameters = new SqlParameter[1]
            {
                new SqlParameter("@Rid",rid)
            };
            return Convert.ToInt32(helper.ExecScalar_Proc(ProcName, commandParameters));
        }
        //public int update(int rid)
        //{
            
        //    //删除以前权限
        //    if(rid>0)
        //    { 
        //    string str = "delete from Role_Option where Rid=" + rid + "";
        //    return Convert.ToInt32(helper.ExecScalar(str));
        //    }
        //    return 0;
        //}
        /// <summary>
        /// 修改权限
        /// </summary>
        /// <param name="Rid"></param>
        /// <param name="Oid"></param>
        /// <returns></returns>
        public int add(int Rid, string Oid)
        {
            if(Rid>0&&Oid!="")
            { 
            string ProcName = "Proc_Add";
            SqlParameter[] commandParameters = new SqlParameter[]
            {
                new SqlParameter("@Rid",Rid),
                new SqlParameter("@Oid",Oid) 
            };
            return Convert.ToInt32(helper.ExecNonquery_Proc(ProcName, commandParameters));
            }
            return 0;
        }
        //public int add(int Rid, string Oid)
        //{

        //    string str = "insert into Role_Option1 values(" + Rid + "," + Oid + ")";

        //    return Convert.ToInt32(helper.ExecScalar(str));
        //}

    }
}
